using System;
using System.Web;

namespace MONA.Modules.Marketing.Controls
{
    public class ItemPage : System.Web.UI.Page
    {
        protected override void OnLoadComplete(EventArgs e)
        {
            base.OnLoadComplete(e);
            if (this.Request.UrlReferrer != null)
                this.ViewState["UrlReferrer"] = this.Request.UrlReferrer.ToString();
        }

        protected void ReturnToReferrerPage()
        {
            // Redirect back.
            if (this.Request.QueryString["ReturnUrl"] != null)
            {
                int pos = this.Request.RawUrl.IndexOf("returnUrl");
                string returnUrl = this.Request.RawUrl.Substring(pos + 10);
                this.Response.Redirect(this.Server.UrlDecode(returnUrl));
            }
            else
            {
                this.Response.Redirect(this.ViewState["UrlReferrer"].ToString());
            }            
        }

        #region Properties (Items)

        private int _ItemID = 0;

        public int ItemID
        {
            get
            {
                if (this._ItemID == 0)
                {
                    if (HttpContext.Current != null && this.Request.Params["ItemID"] != null)
                        this._ItemID = Int32.Parse(this.Request.Params["ItemID"]);
                }
                return this._ItemID;
            }
            set { this._ItemID = value; }
        }

        #endregion
    }
}